public class Demo2 {
    public static boolean isTrue  = true;
    public static void main(String[] args) {
        Thread t1 = new Thread(() -> {
            while (isTrue) {
                System.out.println("t1线程运行");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
            System.out.println("t1线程运行结束");
        });
        Thread t2 = new Thread(() -> {
            try {
                Thread.sleep(2000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("t2线程尝试结束t1线程");
            isTrue = false;
        });
        t1.start();
        t2.start();
    }
}
